/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Admin;

import java.awt.event.*;
import java.util.List;
import javax.persistence.EntityManager;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import supermarket.*;
import model.*;


//import org.jdesktop.beansbinding.Binding;

/**
 *
 * @author aggelos
 */
public class PelatesPanel extends javax.swing.JPanel implements ActionListener, MouseListener {

    public DBmanager db;
    public EntityManager em;
    public int SelectedIndex = -1;
    public JFrame parent;
    public Customer c;
    public CreditCard cc;
    public int customerid;
    public DefaultTableModel Customers_model;
    public DefaultTableModel Checks_model;
    public List<model.Checks> Checks;
    public List<model.Bank> Banks;
    public List<model.Customer> Customers;

    /**
     * Creates new form PelatesPanel
     */
    public PelatesPanel(DBmanager db, JFrame parent) {
        this.parent = parent;
        this.db = db;
        this.em = db.getEm();
        initComponents();

        this.populateCustomersTable();
        this.populateBanksCombo();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        t_customers = new javax.swing.JTable();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        general = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        onoma = new javax.swing.JTextField();
        eponimo = new javax.swing.JTextField();
        dieythinsi = new javax.swing.JTextField();
        arithmosKartas = new javax.swing.JTextField();
        password = new javax.swing.JTextField();
        checks = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        pontoi = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        t_Checks = new javax.swing.JTable();
        b_newCheck = new javax.swing.JButton();
        l_NrOfChecks = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        creditcard = new javax.swing.JPanel();
        ccName = new javax.swing.JTextField();
        ccNumber = new javax.swing.JTextField();
        ccCVV = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        BanksCombo = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        b_create = new javax.swing.JButton();
        b_store = new javax.swing.JButton();
        b_delete = new javax.swing.JButton();

        jPanel1.setBackground(new java.awt.Color(248, 127, 7));
        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N
        jLabel1.setText("Διαχείριση Χρηστών");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jLabel1)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        t_customers.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        t_customers.setFocusable(false);
        t_customers.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        t_customers.setShowVerticalLines(false);
        t_customers.addMouseListener(this);
        jScrollPane1.setViewportView(t_customers);

        jTabbedPane1.setBorder(new javax.swing.border.MatteBorder(null));
        jTabbedPane1.setAutoscrolls(true);

        jLabel2.setText("Ονομα        :");

        jLabel5.setText("Επώνυμο   :");

        jLabel6.setText("Διέυθυνση :");

        jLabel8.setText("Κωδικός              :");

        jLabel11.setText("Αριθμός Κάρτας: ");

        arithmosKartas.setEditable(false);
        arithmosKartas.setBackground(java.awt.SystemColor.control);
        arithmosKartas.setEnabled(false);

        javax.swing.GroupLayout generalLayout = new javax.swing.GroupLayout(general);
        general.setLayout(generalLayout);
        generalLayout.setHorizontalGroup(
            generalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, generalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(generalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel2)
                    .addComponent(jLabel11)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(password, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
                    .addComponent(onoma, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(eponimo, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(dieythinsi, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(generalLayout.createSequentialGroup()
                        .addComponent(arithmosKartas, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 248, Short.MAX_VALUE)))
                .addContainerGap())
        );
        generalLayout.setVerticalGroup(
            generalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(generalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel11)
                    .addComponent(arithmosKartas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel8)
                    .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel2)
                    .addComponent(onoma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel5)
                    .addComponent(eponimo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel6)
                    .addComponent(dieythinsi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Στοιχεία Χρήστη", general);

        checks.setForeground(new java.awt.Color(0, 0, 255));
        checks.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N

        jLabel10.setText("Πόντοι :");

        jLabel12.setText("Επιταγές : (");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, new model.Customer(), org.jdesktop.beansbinding.ELProperty.create("${availablePoints}"), pontoi, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        t_Checks.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Αριθμός Επιταγής", "Ημερομηνία Απόκτησης", "Εγκυρη"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(t_Checks);

        b_newCheck.setText("Νέα Επιταγή Δώρο");
        b_newCheck.addActionListener(this);

        l_NrOfChecks.setText("0");

        jLabel13.setText(")");

        javax.swing.GroupLayout checksLayout = new javax.swing.GroupLayout(checks);
        checks.setLayout(checksLayout);
        checksLayout.setHorizontalGroup(
            checksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(checksLayout.createSequentialGroup()
                .addGroup(checksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 505, Short.MAX_VALUE)
                    .addGroup(checksLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(checksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(checksLayout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pontoi, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(checksLayout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(l_NrOfChecks)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel13)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 184, Short.MAX_VALUE)
                        .addComponent(b_newCheck, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(5, 5, 5))
        );
        checksLayout.setVerticalGroup(
            checksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(checksLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(checksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(checksLayout.createSequentialGroup()
                        .addGroup(checksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(pontoi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(checksLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(l_NrOfChecks)
                            .addComponent(jLabel13)))
                    .addComponent(b_newCheck, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                .addGap(5, 5, 5))
        );

        jTabbedPane1.addTab("Επιταγές και Πόντοι", checks);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, t_customers, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.creditCard.ownerName}"), ccName, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, t_customers, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.creditCard.number}"), ccNumber, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, t_customers, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.creditCard.cvv}"), ccCVV, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jLabel3.setText("Ονομα Τράπεζας    :");

        jLabel4.setText("Ονομα Στην Κάρτα :");

        jLabel7.setText("Αριθμός Κάρτας      :");

        jLabel9.setText("CVV                           :");

        BanksCombo.addActionListener(this);

        javax.swing.GroupLayout creditcardLayout = new javax.swing.GroupLayout(creditcard);
        creditcard.setLayout(creditcardLayout);
        creditcardLayout.setHorizontalGroup(
            creditcardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(creditcardLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(creditcardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel7)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(creditcardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ccNumber, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ccName, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ccCVV)
                    .addComponent(BanksCombo, javax.swing.GroupLayout.Alignment.LEADING, 0, 329, Short.MAX_VALUE))
                .addContainerGap())
        );
        creditcardLayout.setVerticalGroup(
            creditcardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(creditcardLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(creditcardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(BanksCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(creditcardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ccName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(creditcardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ccNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(creditcardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ccCVV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(85, 85, 85))
        );

        jTabbedPane1.addTab("Πιστωτική Κάρτα", creditcard);

        b_create.setText("Δημιουργία");
        b_create.addActionListener(this);

        b_store.setText("Αποθήκευση");
        b_store.addActionListener(this);

        b_delete.setText("Διαγραφή");
        b_delete.addActionListener(this);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(b_create, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(b_store, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(b_delete))
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {b_create, b_delete, b_store});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(b_create)
                .addGap(24, 24, 24)
                .addComponent(b_store)
                .addGap(18, 18, 18)
                .addComponent(b_delete)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTabbedPane1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addComponent(jScrollPane1)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        bindingGroup.bind();
    }

    // Code for dispatching events from components to event handlers.

    public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (evt.getSource() == b_newCheck) {
            PelatesPanel.this.b_newCheckActionPerformed(evt);
        }
        else if (evt.getSource() == BanksCombo) {
            PelatesPanel.this.BanksComboActionPerformed(evt);
        }
        else if (evt.getSource() == b_create) {
            PelatesPanel.this.b_createActionPerformed(evt);
        }
        else if (evt.getSource() == b_store) {
            PelatesPanel.this.b_storeActionPerformed(evt);
        }
        else if (evt.getSource() == b_delete) {
            PelatesPanel.this.b_deleteActionPerformed(evt);
        }
    }

    public void mouseClicked(java.awt.event.MouseEvent evt) {
        if (evt.getSource() == t_customers) {
            PelatesPanel.this.t_customersMouseClicked(evt);
        }
    }

    public void mouseEntered(java.awt.event.MouseEvent evt) {
    }

    public void mouseExited(java.awt.event.MouseEvent evt) {
    }

    public void mousePressed(java.awt.event.MouseEvent evt) {
    }

    public void mouseReleased(java.awt.event.MouseEvent evt) {
    }// </editor-fold>//GEN-END:initComponents

    private void b_createActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_createActionPerformed
        // Εμφάνισε την Jform νέου πελάτη
        NewCustomer NC = new NewCustomer(this);
        parent.setVisible(false);
        // Από εδώ και πέρα ο χειρισμός περνάει στην ανοιχτή φόρμα      
    }//GEN-LAST:event_b_createActionPerformed

    private void t_customersMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_t_customersMouseClicked
        this.SelectedIndex = this.t_customers.getSelectedRow();
        this.c = this.Customers.get(this.SelectedIndex);
        this.cc = this.c.getCreditCard();
        this.customerid = c.getCustomerId();
        //Ενημέρωσε τα textfields της φόρμας
        this.populateCustomerFields();
        //Δείξε τις επιταγές του πελάτη
        this.populateChecksTable();
        this.repaint();
    }//GEN-LAST:event_t_customersMouseClicked

    private void populateCustomerFields() {
        if (this.SelectedIndex != -1) {
            // first tab
            this.arithmosKartas.setText(this.c.getPointsCardNumber());
            this.password.setText(this.c.getPassword());
            this.onoma.setText(this.c.getFirstName());
            this.eponimo.setText(this.c.getLastName());
            this.dieythinsi.setText(this.c.getCustomerAddress());
            // second tab
            this.pontoi.setText(String.valueOf(this.c.getAvailablePoints()));
            // third tab
            if (cc != null) {
                this.ccName.setText(this.cc.getOwnerName());
                this.ccNumber.setText(this.cc.getNumber());
                this.ccCVV.setText(String.valueOf(this.cc.getCvv()));
                //Scroll combo to customer bank
                this.BanksCombo.setSelectedIndex(this.cc.getBank().getBankId() - 1);
            } else {
                this.ccName.setText("");
                this.ccNumber.setText("");
                this.ccCVV.setText(String.valueOf(0));
                //Scroll combo to customer bank
                this.BanksCombo.setSelectedIndex(-1);
            }
        }
    }

    private void readCustomerFields() {
        if (this.SelectedIndex != -1) {
            // first tab
            this.c.setPointsCardNumber(this.arithmosKartas.getText());
            this.c.setPassword(this.password.getText());
            this.c.setFirstName(this.onoma.getText());
            this.c.setLastName(this.eponimo.getText());
            this.c.setCustomerAddress(this.dieythinsi.getText());
            // second tab
            this.c.setAvailablePoints(Integer.parseInt(this.pontoi.getText()));
            // third tab
            if (cc != null) {
                this.cc.setOwnerName(this.ccName.getText());
                this.cc.setNumber(this.ccNumber.getText());
                this.cc.setCvv(Integer.parseInt(this.ccCVV.getText()));
            }

        }
    }

    private void populateBanksCombo() {
        this.Banks = db.getAllBanks();
        //Βάζουμε τα στοιχεία στο Combo 
        for (int i = 0; i < Banks.size(); i++) {
            this.BanksCombo.addItem(Banks.get(i).getName());
        }
    }

    public void populateCustomersTable() {

        this.Customers = db.getAllCustomerList();
        Object[] columnNames = {"ID", "Όνομα", "Επώνυμο", "Διαχειριστής"};
        Customers_model = new DefaultTableModel(new Object[0][0], columnNames);

        this.t_customers.setModel(Customers_model);
        //Βάλε data στον Πίνακα
        for (Customer c1 : Customers) {
            Object[] o = new Object[4];
            o[0] = c1.getCustomerId();
            o[1] = c1.getFirstName();
            o[2] = c1.getLastName();
            o[3] = c1.getIsAdmin();
            Customers_model.addRow(o);
        }

    }

    private void populateChecksTable() {
        // Αν δεν είναι επιλεγμένος κανένας χρήστης φύγε
        if (this.SelectedIndex == -1) {
            return;
        }
        // Πάρε τις επιταγές του χρήστη
        this.Checks = c.getChecksList();
        //φτιάξε DefaultTableModel
        Object[] columnNames = {"Αριθμός Επιταγής", "Ημερομηνία Απόκτησης", "Εγκυρη"};
        Checks_model = new DefaultTableModel(new Object[0][0], columnNames);
        // Ξαναφτιάξε τον πίνακα με νέα data
        for (Checks c1 : Checks) {
            Object[] o = new Object[3];
            o[0] = c1.getCheckId();
            o[1] = c1.getDate();
            if (!c1.getValid()) {
                o[2] = "Ακυρη";
            } else {
                o[2] = "Εγκυρη";
            }
            Checks_model.addRow(o);
        }
        t_Checks.setModel(Checks_model);
        // Δείξε αριθμό επιταγών
        this.l_NrOfChecks.setText(String.valueOf(Checks_model.getRowCount()));
    }

    private void b_storeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_storeActionPerformed
        this.readCustomerFields();

        int result = db.updateCustomer(c);
        int result1 = db.updateCreditCard(cc);
        // Ελεγξε αν ήταν επιτυχής η ενημέρωση
        // και ενημέρωσε χρήστη
        if (result == 1 && result1 == 1) {
            JOptionPane.showMessageDialog(this, SuperMarket.msgSuccModification, SuperMarket.appTitle, JOptionPane.PLAIN_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, SuperMarket.msgUNSuccModification, SuperMarket.appTitle, JOptionPane.PLAIN_MESSAGE);
        }
    }//GEN-LAST:event_b_storeActionPerformed

    private void b_deleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_deleteActionPerformed
        int result = db.deleteCustomer(c);
        // Ελεγξε αν ήταν επιτυχής η ενημέρωση
        // και ενημέρωσε χρήστη
        if (result == 1) {
            JOptionPane.showMessageDialog(this, SuperMarket.msgSuccDeletion, SuperMarket.appTitle, JOptionPane.PLAIN_MESSAGE);
            // Ανανέωσε τις πληροφορίες στον πίνακα      
            this.populateCustomersTable();
        } else {
            JOptionPane.showMessageDialog(this, SuperMarket.msgUNSuccDeletion, SuperMarket.appTitle, JOptionPane.PLAIN_MESSAGE);
        }
    }//GEN-LAST:event_b_deleteActionPerformed

    private void b_newCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_newCheckActionPerformed
        // Αν δεν είναι επιλεγμένος κανένας χρήστης φύγε
        if (this.SelectedIndex == -1) {
            return;
        }
        //Φτιάξε μια επιταγή
        Checks Check = db.newCheck();
        //Συσχετισέ τη με τον πελάτη
        this.c.getChecksList().add(Check);
        Check.getCustomerList().add(c);
        //Ενημέρωσε τον πελάτη στην ΒΔ
        db.updateCustomer(c);
        //Δείξε τις αλαγές
        this.populateChecksTable();
    }//GEN-LAST:event_b_newCheckActionPerformed

    private void BanksComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BanksComboActionPerformed
        // Αν δεν είναι επιλεγμένος κανένας χρήστης φύγε
        if (this.SelectedIndex == -1 || this.BanksCombo.getSelectedIndex() == -1) {
            return;
        }
        // Αλαξε την Τράπεζα στην Κάρτα του Συνδρομητή
        if (this.c.getCreditCard() != null) {
            Bank B = this.Banks.get(this.BanksCombo.getSelectedIndex());
            this.cc.setBank(B);
            db.updateCreditCard(this.cc);
        }
    }//GEN-LAST:event_BanksComboActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox BanksCombo;
    private javax.swing.JTextField arithmosKartas;
    private javax.swing.JButton b_create;
    private javax.swing.JButton b_delete;
    private javax.swing.JButton b_newCheck;
    private javax.swing.JButton b_store;
    private javax.swing.JTextField ccCVV;
    private javax.swing.JTextField ccName;
    private javax.swing.JTextField ccNumber;
    private javax.swing.JPanel checks;
    private javax.swing.JPanel creditcard;
    private javax.swing.JTextField dieythinsi;
    private javax.swing.JTextField eponimo;
    private javax.swing.JPanel general;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel l_NrOfChecks;
    private javax.swing.JTextField onoma;
    private javax.swing.JTextField password;
    private javax.swing.JTextField pontoi;
    private javax.swing.JTable t_Checks;
    private javax.swing.JTable t_customers;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
